//
//  SensorsService.m
//  carutils
//
//  Created by jimu on 12-11-12.
//  Copyright (c) 2012年 3799856@qq.com. All rights reserved.
//

#import "SensorsService.h"

@implementation SensorsService

static BOOL D = NO;

static NSString *pids = @"0105,010B,010C,010D,010F,0110,015A";
+ (NSArray *) pids {
    return [SensorsService getPids];
}

static double engineCoolant;
+ (double) engineCoolant { return (engineCoolant); }

static double map;
+ (double) map { return (map); }

static double engineRpm;
+ (double) engineRpm { return (engineRpm); }

static double maxEngineRpm;
+ (double) maxEngineRpm { return (maxEngineRpm); }

static double avgEngineRpm;
+ (double) avgEngineRpm { return (avgEngineRpm); }

static double engineRpmTotal;
+ (double) engineRpmTotal { return (engineRpmTotal); }

static double vehicleSpeed;
+ (double) vehicleSpeed { return (vehicleSpeed); }

static double maxVehicleSpeed;
+ (double) maxVehicleSpeed { return (maxVehicleSpeed); }

static double avgVehicleSpeed;
+ (double) avgVehicleSpeed { return (avgVehicleSpeed); }

static double vehicleSpeedTotal;
+ (double) vehicleSpeedTotal { return (vehicleSpeedTotal); }

static double intakeTemp;
+ (double) intakeTemp { return (intakeTemp); }

static double airFlowRate;
+ (double) airFlowRate { return (airFlowRate); }

static double acceleratorPedalPosition;
+ (double) acceleratorPedalPosition { return (acceleratorPedalPosition); }

static double maxAcceleratorPedalPosition;
+ (double) maxAcceleratorPedalPosition { return (maxAcceleratorPedalPosition); }

static double avgAcceleratorPedalPosition;
+ (double) avgAcceleratorPedalPosition { return (avgAcceleratorPedalPosition); }

static double acceleratorPedalPositionTotal;
+ (double) acceleratorPedalPositionTotal { return (acceleratorPedalPositionTotal); }

static double testTotalTime;
+ (double) testTotalTime { return testTotalTime; }

static int sp;
+ (int) sp { return sp; }

static double pl = 1.8;
+ (double) pl { return pl; }

static int stopTime;
+ (int) stopTime { return (stopTime); }

static int travelTime;
+ (int) travelTime {  return (travelTime); }

static int totalTime;
+ (int) totalTime { return (totalTime); }

static double travelTotalDistance;
+ (double) travelTotalDistance { return (travelTotalDistance); }

static double avgFuel;
+ (double) avgFuel { return (avgFuel); }

static double realTimeFuel;
+ (double) realTimeFuel { return (realTimeFuel); }


static NSString* vinCode;
+ (NSString *) vinCode: (CACar *) car {
    if (nil == vinCode) {
        [SensorsService vinHandler: car];
        // NSLog(@"vincode is null.");
    }
    
    return (vinCode);
}

+ (void) sensorsDataHandler: (NSString*) data
{    
    
} // sensorsDataHandler

+ (void) vinHandler: (CACar *) car {
    
} // vinHandler:vinData

+ (NSArray *) dataHandler:(NSString *) data isSpecialVinValue:(BOOL) isSpecialVinValue
{
    
} // dataHandler:data isSpecialVinValue:sv

+ (BOOL) detectProtocol: (CACar *) car {
    
} // detectProtocol

+ (void) findRightAccelerator: (CACar *) car {
    
} // findRightAccelerator

+ (NSString *) getSensorsData:(NSString *) pid carObj:(CACar *) car  {
    return [car readOdbDataPid:pid];
} // getSensorsData:pid

+ (NSArray *) getPids {
    return [SensorsService getPids: pids];
} // getPids

+ (NSArray *) getPids:(NSString *) pidStr {
    return [pidStr componentsSeparatedByString:@","];
} // getPids:pidStr


+ (void) calculateFuel {
    
}

+ (void) calculateTraveData {
    
}

+ (void) calculateVehicleSpeedAvg {
    vehicleSpeedTotal += vehicleSpeed;
    avgVehicleSpeed = vehicleSpeedTotal / totalTime;
}

+ (void) calculateAcceleratorPedalPositionAvg {
    acceleratorPedalPositionTotal += acceleratorPedalPosition;
    avgAcceleratorPedalPosition = acceleratorPedalPositionTotal / totalTime;
}

+ (void) calculateEngineRpmAvg {
    engineRpmTotal += engineRpm;
    avgEngineRpm = engineRpmTotal / totalTime;
}

+ (void) calculateTravelTotalDistance {
    travelTotalDistance += vehicleSpeed * 1 / 3600;
}

+ (void) calculateIdlingFuel: (int)stopTimeCount {
    
}

+ (void) testing: (double) intervalTime {

}

// 获取故障码
+ (NSMutableArray *) dtcs {
    NSMutableArray *arrs = [NSMutableArray arrayWithCapacity: 10];
    [arrs addObject: @"P2029"];
    [arrs addObject: @"P0082"];
    [arrs addObject: @"U0021"];
    [arrs addObject: @"B0090"];
    [arrs addObject: @"C0032"];
    
    return arrs;
}
@end
